import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        token: '',
        userName: ''
    },

    getters: {
        getToken(state) {
            return state.token || localStorage.getItem('token') || ''
        }
    },

    mutations: {
        setToken(state, token) {
            state.token = token
            localStorage.setItem('token', token)
            console.log('store & localStorage update token!')
        },
        removeToken(state) {
            state.token = ''
            localStorage.removeItem('token')
        }
    }
})

export default store